package com.augurit.smartform.database;

import java.util.ArrayList;
import java.util.List;

import com.augurit.smartform.database.change.ColumnChangeInfo;
import com.augurit.smartform.database.change.CopyDataInfo;

/**
 * 根据不同的操作对SQL语句进行封装的工具类
 * @author cuigeqiang
 *
 */
public class SQLWrapper {
	private SQLWrapper(){}
	
	/**
	 * 创建跟表相关的内容（表，序列，约束）
	 * @param table
	 * @return
	 * cuigeqiang
	 */
	public static List<String> createAny(Table table){
		List<String> allCreateSQL=new ArrayList<String>();
		String createSequence=SQLGenerator.getCreateSequence(table);
		allCreateSQL.add(createSequence);
		String createTable=SQLGenerator.getCreateTable(table);
		allCreateSQL.add(createTable);
		String addPrimaryKey=SQLGenerator.getAddPrimaryKey(table);
		allCreateSQL.add(addPrimaryKey);
		List<String> createAllIndex=SQLGenerator.getCreateAllIndex(table);
		allCreateSQL.addAll(createAllIndex);
		List<String> addAllUnique=SQLGenerator.getAddAllUnique(table);
		allCreateSQL.addAll(addAllUnique);
		List<String> addAllForeignKey=SQLGenerator.getAddAllForeignKey(table);
		allCreateSQL.addAll(addAllForeignKey);
		return allCreateSQL;
	}
	
	/**
	 * 将数据从旧版本拷贝到新版本
	 * @param copyDataInfo
	 * @return
	 * cuigeqiang
	 */
	public static List<String> copyTableData(CopyDataInfo copyDataInfo){
		List<String> aLLCopyTableSQL=new ArrayList<String>();
		String copyTableSQL=SQLGenerator.getCopyTableData(copyDataInfo);
		aLLCopyTableSQL.add(copyTableSQL);
		return aLLCopyTableSQL;
	}
	
	/**
	 * 将序列从旧版本拷贝到新版本
	 * @param copyDataInfo
	 * @return
	 * cuigeqiang
	 */
	public static List<String> copySequence(CopyDataInfo copyDataInfo){
		return SQLGenerator.getCopySequence(copyDataInfo);
	}
	
	/**
	 * 删除跟表相关的内容（约束，序列，表）
	 * @param table
	 * @return
	 * cuigeqiang
	 */
	public static List<String> dropAny(Table table){
		List<String> allDropSQL=new ArrayList<String>();
		String dropSequence=SQLGenerator.getDropSequence(table);
		allDropSQL.add(dropSequence);
		String dropTableCC=SQLGenerator.getDropTableCascadeConstraint(table);
		allDropSQL.add(dropTableCC);
		return allDropSQL;
	}
	
	/**
	 * 增加数据库列
	 * @param columnChangeInfo
	 * @return
	 * cuigeqiang
	 */
	public static List<String> addColumn(ColumnChangeInfo columnChangeInfo){
		List<String> allAddColumnSQL=new ArrayList<String>();
		String allAddColumn=SQLGenerator.getAddColumn(columnChangeInfo);
		allAddColumnSQL.add(allAddColumn);
		return allAddColumnSQL;
	}
	
	/**
	 * 删除数据库列
	 * @param columnChangeInfo
	 * @return
	 * cuigeqiang
	 */
	public static List<String> delColumn(ColumnChangeInfo columnChangeInfo){
		List<String> allDelColumnSQL=new ArrayList<String>();
		String allDelColumn=SQLGenerator.getDelColumn(columnChangeInfo);
		allDelColumnSQL.add(allDelColumn);
		return allDelColumnSQL;
	}
	
	/**
	 * 重命名列
	 * @param columnChangeInfo
	 * @return
	 * cuigeqiang
	 */
	public static List<String> renameColumn(ColumnChangeInfo columnChangeInfo){
		return SQLGenerator.getRenameColumn(columnChangeInfo);
	}
	
	/**
	 * 修改数据库列长度、精度、标度、默认值、是否为空、唯一键、索引等信息
	 * @param columnChangeInfo
	 * @return
	 * cuigeqiang
	 */
	public static List<String> modifyColumn(ColumnChangeInfo columnChangeInfo){
		return SQLGenerator.getModifyColumn(columnChangeInfo);
	}
	
	/**
	 * 给一个数据表插值
	 * @param table
	 * @return
	 * cuigeqiang
	 */
	public static List<String> insertTable(Table table){
		List<String> insertSQL=new ArrayList<String>();
		List<String> insertTable=SQLGenerator.getInsertTable(table);
		insertSQL.addAll(insertTable);
		return insertSQL;
	}
	
	/**
	 * 查询数据表
	 * @param table
	 * @return
	 * cugeqiang
	 */
	public static String selectTable(Table table){
		return SQLGenerator.getSelectTable(table);
	}
	
	/**
	 * 查询数据表ID
	 * @param table
	 * @return
	 * cugeqiang
	 */
	public static String selectTableId(Table table){
		return SQLGenerator.getSelectTableId(table);
	}
	
	/**
	 * 更新数据表
	 * @param table
	 * @return
	 * cugeqiang
	 */
	public static List<String> updateTable(Table table){
		List<String> updateSQL=new ArrayList<String>();
		String updateTable=SQLGenerator.getUpdateTable(table);
		updateSQL.add(updateTable);
		return updateSQL;
	}
	
	/**
	 * 删除表数据
	 * @param table
	 * @return
	 * cugeqiang
	 */
	public static List<String> deleteTable(Table table){
		List<String> deleteSQL=new ArrayList<String>();
		String deleteTable=SQLGenerator.getDeleteTable(table);
		deleteSQL.add(deleteTable);
		return deleteSQL;
	}
	
	/**
	 * 批量删除表数据
	 * @param table
	 * @param ids
	 * @return
	 * cuigeqiang
	 */
	public static List<String> deleteTable(Table table,String[] ids){
		List<String> deleteSQL=new ArrayList<String>();
		String deleteTable=SQLGenerator.getDeleteTable(table,ids);
		deleteSQL.add(deleteTable);
		return deleteSQL;
	}
}
